//
//  ViewController.m
//  11106
//
//  Created by student on 16/3/6.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>

@property (nonatomic,weak) UIScrollView *scrollView;
@property (nonatomic,strong) NSArray *picArr;
@property (nonatomic,weak) UIPageControl *page;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.picArr = @[@"guide0",@"guide1",@"guide2",@"guide3"];
    int width = [UIScreen mainScreen].bounds.size.width;
    int height = [UIScreen mainScreen].bounds.size.height-22;
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 22, width, height)];
    scrollView.pagingEnabled = YES;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.contentSize = CGSizeMake(width*4, 0);
    self.scrollView = scrollView;
    [self.view addSubview:self.scrollView];
    
    for (int i = 0; i < 4; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(width*i , 0, width, height)];
        [imageView setImage:[UIImage imageNamed:self.picArr[i]]];
        [self.scrollView addSubview:imageView];
    }
    UIPageControl *page = [[UIPageControl alloc] initWithFrame:CGRectMake((width-50)/2, height-40, 50, 20)];
    page.numberOfPages = 4;
    page.pageIndicatorTintColor = [UIColor yellowColor];
    page.currentPageIndicatorTintColor = [UIColor redColor];
    self.page = page;
    [self.view addSubview:self.page];
    self.scrollView.delegate = self;
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int width = [UIScreen mainScreen].bounds.size.width;
    self.page.currentPage = self.scrollView.contentOffset.x / width;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
